package com.umeox.watch.moto.dataservice.mqtt.impl;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.umeox.watch.moto.dataservice.base.BaseApp;
import com.umeox.watch.moto.dataservice.mqtt.DataHandleManager;
import com.umeox.watch.moto.dataservice.mqtt.interfaces.IPublishListener;
import com.umeox.watch.moto.dataservice.mqtt.interfaces.IResultCallBack;
import com.umeox.watch.moto.dataservice.mqtt.service.MqttService;


public class MqttServiceDelegate {

    @SuppressLint("NewApi")
    public static void startService(Context context) {

        Intent svc = new Intent(context, MqttService.class);
        svc.setAction(MqttService.MQTT_CONNECT_INTENT);
        context.startService(svc);
    }

    public static void stopService(Context context) {
        Intent svc = new Intent(context, MqttService.class);
        context.stopService(svc);
    }

    public static void sendEvent(String event ,Object data, IPublishListener listener){
        MqttService.getInstance().sendEvent(event,data,listener);
    }

    public static void requestAttributes(JSONArray attributes, IPublishListener listener){
        MqttService.getInstance().requestAttributes(attributes,listener);
    }

    public static void rpcResponse(String topic, String method,Object message,IPublishListener listener){
        MqttService.getInstance().rpcResponse(topic,method,message,listener);
    }

    public static void ackPushMsg(String responseTopic, JSONObject ack) {
        MqttService.getInstance().ackPushMsg(responseTopic,ack);
    }

    @SuppressWarnings("unchecked")
    public static void requestFriends(Object message, IPublishListener listener, IResultCallBack<Integer> resultCallBack){
        DataHandleManager.getInstance().setResultCallBack(resultCallBack);
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void sendChatMsg(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    @SuppressWarnings("unchecked")
    public static void sendChatMsg(Object message, IPublishListener listener,IResultCallBack<String> resultCallBack) {
        String requestId = BaseApp.getInstance().createRequestId();
        DataHandleManager.getInstance().setChatMsgResultCallBack(Integer.valueOf(requestId),resultCallBack);
        MqttService.getInstance().requestChatMsgClientRpc(requestId,message,listener);
    }

    public static void getVoipToken(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void reqVoipCall(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void getFileSign(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void getDeviceCode(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void getLastPosition(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void uploadHotVer(JSONObject jsonObject, IPublishListener listener) {
        MqttService.getInstance().uploadHotVer(jsonObject,listener);
    }

    public static void getStoriesPage(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }

    public static void getRecommendStories(Object message, IPublishListener listener) {
        MqttService.getInstance().requestClientRpc(message,listener);
    }
}
